/*
 * (C) APUE
 * Implementation of sigset operation: initialization, add and delete
 * We assume that 31 types of signals and 32 bits of integer
 */
//#include <signal.h>
#include <errno.h>

typedef int sigset_t;
#define	NSIG	32

/* <signal.h> usually defines NSIG to include signal number 0 */
#define SIGBAD(signo)	((signo) <= 0 || (signo) >= NSIG)

int sigaddset(sigset_t *set, int signo)
{
	if (SIGBAD(signo)) {errno = EINVAL; return (-1);}
	*set |= 1 << (signo - 1);
	return 0;
}

int sigdelset(sigset_t *set, int signo)
{
	if (SIGBAD(signo)) {errno = EINVAL; return (-1);}
	*set &= ~(1 << (signo - 1));
	return 0;
}

int sigismember(const sigset_t *set, int signo)
{
	if (SIGBAD(signo)) {errno = EINVAL; return (-1);}
	return ((*set) & (1 << (signo - 1)));
}
